package com.tangula.web.kashine.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.tangula.controller.ReturnRespController;
import com.tangula.core.Context;
import com.tangula.core.Controller;
import com.tangula.web.config.auth.Ignore;

import com.tangula.web.kashine.business.LoginBusiness;
import com.tangula.web.kashine.entity.AccountEntity;
import com.tangula.web.kashine.entity.BaseRespEntity;
import com.tangula.web.kashine.entity.LoginForm;
import com.tangula.web.kashine.entity.UpLoadImageForm;

@RestController
@RequestMapping("/loginController")
@ResponseBody

public class LoginController implements Controller<Context>, ReturnRespController,AuthController{
	@Autowired
	LoginBusiness loginBusiness;

	/**
	 * 登录
	 * @param user .
	 * @return .
	 */
	@RequestMapping(value = "/login",consumes = "application/json",method = {RequestMethod.POST })
	@Ignore
	public ResponseEntity<BaseRespEntity<AccountEntity>> signup(@RequestBody LoginForm account) {
		return returnSuccess(loginBusiness.signup(account));
	}
	/**
	 * 输入email返回实体
	 * @param user .
	 * @return .
	 */
	@RequestMapping(value = "/loadAccount",consumes = "application/json",method = {RequestMethod.POST })
	@Ignore
	public ResponseEntity<BaseRespEntity<AccountEntity>> loadAccout(String email){
		return returnSuccess(loginBusiness.loadAccount(email));
	}
	/**
	 * 注册
	 * @param user .
	 * @return .
	 */
	@RequestMapping(value = "/signUp",consumes = "application/json",method = {RequestMethod.POST })
	@Ignore
	public ResponseEntity<BaseRespEntity<AccountEntity>> register(@RequestBody AccountEntity account) {
		return returnSuccess(loginBusiness.register(account));
	}
	/**
	 * 用户更改头像
	 * @param user .
	 * @return .
	 */
	@RequestMapping(value = "/upLoadAccountImage",consumes = "application/json",method = {RequestMethod.POST })
	@Ignore
	public ResponseEntity<BaseRespEntity<Boolean>> upLoadAccountImage(@RequestBody UpLoadImageForm image) {
		return returnSuccess(loginBusiness.upLoadAccountImage(image)!=null);
	}
}
